package com.binance.gateway.app.base.helper;

import com.binance.master.old.models.sys.SysConfig;
import com.binance.master.utils.StringUtils;
import com.binance.sysconf.service.SysConfigVarCacheService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * PNK系统数据库配置表读取实现类
 * <p>
 * Created by Fei.Huang on 2018/8/8.
 */
@Component
@Slf4j
public class SysConfigHelper {

    @Autowired
    private SysConfigVarCacheService sysConfigVarCacheService;

    /**
     * 兼容原有代码,否则建议直接使用getCodeByDisplayName
     *
     * @param displayName
     * @return
     */
    public SysConfig selectByDisplayName(String displayName) {
        SysConfig sysConfig = null;
        if (StringUtils.isNotEmpty(displayName)) {
            String code = sysConfigVarCacheService.getValue(displayName);
            if (code != null) {
                sysConfig = new SysConfig();
                sysConfig.setDisplayName(displayName);
                sysConfig.setCode(code);
            }
        }
        return sysConfig;
    }

    public String getCodeByDisplayName(String displayName) {
        return sysConfigVarCacheService.getValue(displayName);
    }
}